#ifndef DOORSTATUS_H
#define DOORSTATUS_H

#include <QWidget>
#include "QTimer"

namespace Hydra_DoorStatus {

typedef enum _door_state {
    INIT,                   // 初始态
    FORCE_ENABLE,           // 强制门允许
    BOTH_ENABLE,            // 允许左右两侧车门同时开启
    LEFT_ENABLE,            // 允许左侧车门开启
    RIGHT_ENABLE,           // 允许右侧车门开启
    LEFT_OPEN,              // 左侧车门打开
    RIGHT_OPEN,             // 右侧车门打开
    BOTH_OPEN,              // 左右侧车门均打开
    OPEN_WITHOUT_ENABLE     // 无门允许情况下车门打开
}DOORSTATE;


typedef enum _open_side {
    LEFT,
    RIGHT,
    BOTH
}OPENSIDE;

}


using namespace Hydra_DoorStatus;


class DoorStatus : public QWidget
{
    Q_OBJECT

public:
    DoorStatus(QWidget *parent = 0);

    void setInterval(quint16 interval);                                                                 // 设置刷新频率
    void setImageHeightProportion(quint8 value);                                                        // 设置图形高度占控件高度百分比
    void setImageWidthProportion(quint8 value);                                                         // 设置图形宽度占控件宽度百分比
    void setHorizontalSpace(quint8 value);                                                              // 设置横向间隔宽度
    void setDoorState(DOORSTATE state);                                                                 // 设置状态

public slots:
    void refresh();


protected:
    void paintEvent(QPaintEvent *event);
    void resizeEvent(QResizeEvent *event);
    void initParam();
    void drawImage(QPainter *pPainter);                                                                 // 绘制图形


    void drawDoor(QPainter *pPainter, OPENSIDE side, QColor color);                                     // 绘制车门允许
    void drawOpenSide(QPainter *pPainter, OPENSIDE side);                                               // 绘制开门侧
    void drawForceEnable(QPainter *pPainter);                                                           // 绘制强制门允许




private:
    QTimer mTimer;
    QPoint mCenterPoint;                                                                                // 控件中心
    quint8 mImageHeightProportion = 65;                                                                 // 图形高度占控件高度百分比
    quint16 mImageHeight;                                                                               // 图形高度
    quint8 mImageWidthProportion = 50;                                                                  // 图形宽度占控件宽度百分比
    quint16 mImageWidth;                                                                                // 图形宽度
    quint8 mHorizontalSpace = 3;                                                                        // 横向间隔宽度
    quint8 mVerticalSpace = 3;                                                                          // 竖向间隔宽度
    quint16 mSingleShapeWidth;                                                                          // 除强制门允许意外的图形中单个完整图形(比如三角形,矩形)宽度
    DOORSTATE mDoorState = DOORSTATE::INIT;                                                             // 门状态(默认:初始态)
    QColor mDoorEnableColor = QColor(212, 212, 212);                                                    // 门使能颜色
    QColor mDoorOpenColor = QColor(255, 242, 0);                                                        // 门打开颜色
    QColor mOpenSideColor = QColor(255, 242, 0);                                                        // 开门侧颜色
    quint8 mOutSideRectLineWidth = 4;                                                                   // 强制门允许时外边框矩形线条宽度
    QColor mOutSideRectColor = QColor(189, 0, 0);                                                       // 强制门允许时外边框矩形线条颜色
    QColor mArrowColor = QColor(189, 0, 0);                                                             // 强制门允许时外边框矩形箭头颜色
};


#endif // DOORSTATUS_H
